package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDev;
import com.ruoyi.system.service.ISysDevService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author alph
 * @date 2020-12-25
 */
@RestController
@RequestMapping("/system/dev")
public class SysDevController extends BaseController
{
    @Autowired
    private ISysDevService sysDevService;

    /**
     * 查询设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:dev:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDev sysDev)
    {
        startPage();
        List<SysDev> list = sysDevService.selectSysDevList(sysDev);
        return getDataTable(list);
    }

    /**
     * 导出设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:dev:export')")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysDev sysDev)
    {
        List<SysDev> list = sysDevService.selectSysDevList(sysDev);
        ExcelUtil<SysDev> util = new ExcelUtil<SysDev>(SysDev.class);
        return util.exportExcel(list, "dev");
    }

    /**
     * 获取设备管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dev:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysDevService.selectSysDevById(id));
    }

    /**
     * 新增设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:dev:add')")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDev sysDev)
    {
        return toAjax(sysDevService.insertSysDev(sysDev));
    }

    /**
     * 修改设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:dev:edit')")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDev sysDev)
    {
        return toAjax(sysDevService.updateSysDev(sysDev));
    }

    /**
     * 删除设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:dev:remove')")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysDevService.deleteSysDevByIds(ids));
    }
}
